package books

import static org.junit.Assert.*
import org.junit.*

class BookServiceIntegrationTests {

	def bookService
	
	void testStaticBook() {
		def staticBook = bookService.getStaticBook()
		assertEquals("Old MacDonald had a farm", staticBook.title)
		assertEquals("Some guy", staticBook.author)
		assertEquals("A story about a farmer and his animals", staticBook.description)
		assertEquals(0, staticBook.minGradeLevel)
		assertEquals(6, staticBook.maxGradeLevel)
		assertEquals("English", staticBook.language)
		assertEquals("General Leisure Reading", staticBook.category)	
	}
	
	void testRandomBook() {
		def randomBook = bookService.getRandomBook()
		assertNotNull(randomBook)
	}
	
	void testValidISBN() {
		def isbn1 = "978-0-12-385059-1"
		def isbn2 = "978-0-596-80095-6"
		def isbn3 = "978-0-262-63-854-3"
		def isbn4 = "978-0-130-08215-2"
		def isbn5 = "978-0-534-9534-16"
		def isbn6 = "978-216-148-0"
		def isbn7 = "9793988932"
		assertTrue(bookService.getValidISBN(isbn1.replaceAll("-","")))
		assertTrue(bookService.getValidISBN(isbn2.replaceAll("-","")))
		assertTrue(bookService.getValidISBN(isbn3.replaceAll("-","")))
		assertTrue(bookService.getValidISBN(isbn4.replaceAll("-","")))
		assertTrue(bookService.getValidISBN(isbn5.replaceAll("-","")))
		assertTrue(bookService.getValidISBN(isbn6.replaceAll("-","")))
		assertTrue(bookService.getValidISBN(isbn7.replaceAll("-","")))
	}
}
